//
//  UserMessageController.m
//  pmmSS
//
//  Created by Mac book on 2017/9/19.
//  Copyright © 2017年 WTFSSD. All rights reserved.
//

#import "UserMessageController.h"
#import "UserIconImageCell.h"
#import "UserMessageCell.h"
#import "ChangePassWordController.h"

@interface UserMessageController ()
@property (nonatomic,strong) NSArray *dataArray;


@end

@implementation UserMessageController


-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];

    [self setUpNavBar];

}
-(void)viewDidLoad{

    [super viewDidLoad];

     [self setTableView:self.tableView];

    _dataArray = @[@[@"用户昵称",@"手机号",@"修改密码"],@[@"O(∩_∩)O哈！",@"13566889955",@""]
                    ];

}
-(void)setUpNavBar{


    UILabel *title_label = [HMLabel createLabelWithText:@"个人中心" andTextColor:[UIColor whiteColor] andBgColor:nil andFont:[UIFont fontWithName:default_fontname size:autoScaleW(20)] andTextAlignment:NSTextAlignmentCenter];

    title_label.frame = CGRectMake(0, 0, 100, 35);

    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav_bgimage"] forBarMetrics:UIBarMetricsDefault];

    self.navigationItem.titleView = title_label;



    UIButton *leftBtn = [HMButton createButtonWithTitle:@"" andTitleColor:nil andBgColor:nil andImage:[UIImage imageNamed:@"icon_arrow_left_white"] andBgImage:nil andSelecter:@selector(clickButton:) andTarget:self andTag:101];
    leftBtn.frame = CGRectMake(0, 0, autoScaleW(60), autoScaleW(30));
    [leftBtn setImageEdgeInsets:UIEdgeInsetsMake(autoScaleH(7), 0, autoScaleH(7), autoScaleW(50))];

    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];

    [self.navigationItem setLeftBarButtonItem:leftItem];
    
    
}


-(void)setTableView:(UITableView *)tableView{


    tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);

    
   [tableView registerClass:[UserIconImageCell class] forCellReuseIdentifier:@"UserIconImageCell"];


    [tableView registerClass:[UserMessageCell class] forCellReuseIdentifier:@"UserMessageCell"];


}

#pragma mark : UITableViewDelegate  &&   UITableViewDataSource


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return section == 0?1:3;

    //return 2;

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{


    if (indexPath.section == 0) {

        static  NSString *cellId = @"UserIconImageCell";
        
             UserIconImageCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        cell.selectionStyle =UITableViewCellSelectionStyleNone;


        return cell;


    }else{


          static  NSString *cellId = @"UserMessageCell";

          UserMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];

          cell.selectionStyle =UITableViewCellSelectionStyleNone;

            cell.titleLabel.text = _dataArray[0][indexPath.row];

            cell.subLabel.text = _dataArray[1][indexPath.row];

            return cell;
      

    }

    return [[UITableViewCell alloc] init ];


}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{


   return section == 0?0.f:10;

}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return indexPath.section == 0?autoScaleH(70):autoScaleH(50);
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section == 0) {

            [self showImagePickerWith:^(UIImage *selectedImage) {

                NSLog(@"%@",selectedImage);

       //上传照片



            }];


    }else{

        if (indexPath.row == 0) {


        } else if (indexPath.row == 1){


        }else if (indexPath.row == 2){

            ChangePassWordController * vc = [[ ChangePassWordController alloc]init];

            [self.navigationController pushViewController:vc animated:YES];

        }

    }

}
-(void)clickButton:(UIButton *)button{

    [self.navigationController popViewControllerAnimated:YES];
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
